package jataaka.parser;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;

public abstract class BaseParserService {

	
	/**
	 * retrieves next line from stream
	 * @return retrieves next line from stream
	 * @throws IOException 
	 */
	public static String retrieveNextLine(BufferedReader reader) throws IOException{
		for (String line; (line = reader.readLine()) != null;) {
			return line;
		}
		return null;
	}
	
	
	/**
	 * returns the stream for read of a url
	 * @return returns the stream for read of a url
	 * @throws IOException 
	 */
	public static BufferedReader createStreamForRead(String stringURL) throws IOException{
		URL url = new URL(stringURL);
		InputStream response = url.openStream();
		return new BufferedReader(new InputStreamReader(response));
	}
	
	/**
	 * detemines if the line analyzed is the beginning of a parseable structure
	 * @param line the line to be analyzed
	 */
	public abstract boolean isLineBeginOnParseableStructure(String line);
	
}
